ID, '_gist_id', true ) ; $gist_id = ! empty( $gist_id ) ? $gist_id : ''; $gist_data = get_post_meta( $data->ID, '_gist_data', true ); $gist_data = ! empty( $gist_data ) ? $gist_data : array(); $files = ''; if ( ! empty( $gist_data ) ) { foreach ( $gist_data as $file => $data ) $files .= '
{' . $file . '}
(.+?)<\/pre>/is', $gist_body->div, $gist_divs ); $gist_divs = $gist_divs[0]; foreach ( $gist_files as $i => $gist_file ) $gist_data[ $gist_file ] = '' . $gist_divs[$i] . ''; foreach ( $gist_data as $file => $gist_item ) { $gist_new_meta = sprintf( '', esc_url( "https://gist.github.com/raw/{$gist_id}/{$file}" ), esc_url( "https://gist.github.com/gists/{$gist_id}/download"), esc_url( "https://gist.github.com/{$gist_id}") ); $gist_data[ $file ] .= $gist_new_meta; } update_post_meta( $post_id, '_gist_data', $gist_data ); die( json_encode( array( 'id' => $gist_id, 'files' => $gist_files ) ) ); } /* * AJAX callback function which handles the API response. Saves the data * into custom fields */ function ds_convert_to_gist( $content ) { $gist_data = get_post_meta( get_the_ID(), '_gist_data', true ); if ( empty( $gist_data ) ) return $content; wp_enqueue_style('gist-css'); foreach ( $gist_data as $file => $file_data ) { $files[] = '/{' . $file . '}/'; $data[] = $file_data; } $content = preg_replace( $files, $data, $content ); return $content; }